<template>
  <div class="complain">
    <!-- 搜索条件 -->
    <el-form
      ref="complainForm"
      :model="complainForm"
      label-width="80px"
      size="small"
      :inline="true"
    >
      <el-form-item label="openId">
        <el-input v-model="complainForm.openid"></el-input>
      </el-form-item>
      <el-form-item label="投诉类型">
        <el-select v-model="complainForm.type" placeholder="请选择投诉类型">
          <el-option label="订单相关投诉" value="0"></el-option>
          <el-option label="交易相关投诉" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="投诉状态">
        <el-select v-model="complainForm.state" placeholder="请选择投诉状态">
          <el-option label="未处理" value="0"></el-option>
          <el-option label="已处理" value="1"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="发布时间">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="complainForm.publish_time"
            style="width: 200%"
          ></el-date-picker>
        </el-col>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="onSearch">查找</el-button>
      </el-form-item>
    </el-form>
    <!-- 投诉列表 -->
    <div class="complain-table">
      <el-table
        :data="formateList(complainList)"
        height="380"
        border
        style="width: 100%; max-width: 1500px"
      >
        <el-table-column
          prop="order_id"
          label="订单编号"
          width="250"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="openid"
          label="openId"
          width="260"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="state"
          label="投诉状态"
          width="150"
          align="center"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="publish_time"
          label="发布时间"
          width="150"
          align="center"
        >
        </el-table-column> -->
        <!-- <el-table-column
          prop="publisher"
          label="发布人"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="contact"
          label="联系方式"
          width="150"
          align="center"
        >
        </el-table-column> -->
        <el-table-column
          prop="type"
          label="投诉类型"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="text"
          label="投诉内容"
          width="235"
          align="center"
        >
        </el-table-column>
        ><el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-popconfirm
              title="处理该投诉吗？"
              @confirm="dealComplain(scope.row)"
            >
              <el-button type="text" size="small" slot="reference"
                >处理</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 详情弹出框 -->
    <el-dialog title="投诉内容" :visible.sync="dialogVisible" width="30%">
    </el-dialog>
  </div>
</template>

<script>
import complainApi from "@/api/complain";
export default {
  name: "Complain",
  data() {
    return {
      dialogVisible: false,
      complainForm: {
        openid: "",
        type: [],
        state: [],
        publish_time: "",
      },
      complainList: [],
      state: ["未处理", "已处理"],
      type: ["订单相关投诉", "交易相关投诉"],
    };
  },
  created() {
    console.log("complain created");
    this.getList();
  },
  methods: {
    // 获取投诉列表
    async getList() {
      const res = await complainApi.getComplain();
      console.log(res);
      this.complainList = res.data;
    },
    // 重组订单列表
    formateList(list) {
      return list.map((item) => {
        let tempItem = {
          ...item,
        };
        tempItem.state = this.state[tempItem.state];
        tempItem.type = this.type[tempItem.type - 1];
        return tempItem;
      });
    },
    // 查询
    async onSearch() {
      const res = await complainApi.searchComplain(this.complainForm);
      console.log(res);
      this.complainList = res.data
    },
    // 处理投诉
    async dealComplain(row) {
      console.log(row);
      const res = await complainApi.dealComplain(row.order_id);
      console.log(res);
      this.$message({
        message: "处理成功",
        type: "success",
      });
      this.getList()
    },
  },
};
</script>

<style scoped lang="less">
.complain {
  padding: 30px;
  .complain-table {
    margin-top: 25px;
    margin-left: 10px;
  }
}
</style>